package com.zhang.configs;

import com.zhang.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //注入IOC容器
public class WebConfig implements WebMvcConfigurer {

    //拦截器对象
    @Autowired
    private LoginInterceptor loginInterceptor;

    //重写addInterceptors方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器，但是登录和注册的地址不拦截
        registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login","/user/register");
    }
}
